package denglu.Dao;

import org.apache.ibatis.annotations.*;
import denglu.utity.User;

import java.util.List;
import java.util.Map;
/**
 * Created by ECHO on 2018/7/30.
 */
@Mapper
public interface UserDAO {

    //通过name查询
    @Select("SELECT * FROM user WHERE name = #{name}")
    User findByName(@Param("name") String name);

    //通过id查询
    @Select("SELECT * FROM user WHERE id = #{id}")
    User findById(@Param("id") int id);

    //map映射
    @Results({
            @Result(property = "name", column = "name"),
            @Result(property = "country", column = "country"),
            @Result(property = "length", column = "length")
    })

    //查询全部
    @Select("SELECT name, country , length FROM user")
    List<User> findAll();

    //通过详细信息直接添加
    @Insert("INSERT INTO user(name, country , length) VALUES(#{name}, #{country}, #{length})")
    int insert(@Param("name") String name, @Param("country") String country, @Param("length") Integer length);

    //通过实体类user识别id更新
    @Update("UPDATE user SET name=#{name}, country=#{country}, length=#{length} WHERE id=#{id}")
    void update(User user);

    //根据name修改id
    @Update("UPDATE user SET id=#{id} WHERE name=#{name}")
    void updateId(User user);

    //根据id删除
    @Delete("DELETE FROM user WHERE id =#{id}")
    void delete(int id);

    //通过实体类user添加
    @Insert("INSERT INTO user(name, country, length) VALUES(#{name}, #{country}, #{length})")
    int insertByUser(User user);

    //通过map添加
    @Insert("INSERT INTO user(name, country, length) VALUES(#{name,jdbcType=VARCHAR}, #{country,jdbcType=VARCHAR}, #{length,jdbcType = INTEGER})")
    int insertByMap(Map<String, Object> map);








}
